package demo.blue.service;

import blue.base.core.http.HttpClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author Jin Zheng
 * @since 1.0 2021-07-14
 */
@Component
public class TestService {
	private static Logger logger = LoggerFactory.getLogger(TestService.class);

	private HttpClient testClient;

	public TestService() {
	}

	public String getSource(String name) {
		String url = "/test/" + name;
		var response = testClient.requestSync(url);
		logger.info("url: {}, method: GET, header: {}, body: {}", url, response.getHeaders(), response.getBody());
		return response.getBody();
	}

	@Autowired
	public void setTestClient(HttpClient testClient) {
		this.testClient = testClient;
	}
}
